package cn.com.dealme.nutz.view;

import java.util.Map;

import org.nutz.json.Json;
import org.nutz.json.JsonFormat;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.view.UTF8JsonView;

import cn.com.dealme.DealMeRuntimeException;
import cn.com.dealme.error.ErrMsgManager;
import cn.com.dealme.error.ErrorMap;

public class DJsonErrMapView extends DJsonView {
	
	private static final Log log = Logs.getLog(UTF8JsonView.class);
	
	public DJsonErrMapView(Object data) {
		super(data);
	}
	
	public DJsonErrMapView(DealMeRuntimeException e) {
		super(null);
		Map<String, String> map = ErrorMap.makeErrMap();
		map.put(e.getKey(),
				ErrMsgManager.getResource(e.getMessage()));
		super.setData(map);
		if(log.isDebugEnabled()) {
			log.debug("write json: " + Json.toJson(map, JsonFormat.compact()));
		}
	}

}
